package newProject;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.io.InputStream;

public class XJiangJFrame{
    JFrame jframe=new JFrame("扫号器");//创建并设置窗口名

    JPanel jPanel0=new JPanel();//用来加下面123456 的
    JPanel jPanel1=new JPanel();
    JPanel jPanel2=new JPanel();
    JPanel jPanel3=new JPanel();
    JPanel jPanel4=new JPanel();
    JPanel jPanel5=new JPanel();
    JPanel jPanel6=new JPanel();
    JPanel jPanel7=new JPanel();

    JLabel jlabel1=new JLabel("类型:不带4和7");
    JLabel jlabel2=new JLabel("类型:中间三A");
    JLabel jlabel3=new JLabel("类型:中间3A");
    JLabel jlabel4=new JLabel("类型:ABCD");
    JLabel jlabel5=new JLabel("类型:**ab**ab");
    JLabel jLabel6=new JLabel("类型:其他");
    JLabel jlabel7=new JLabel("输入扫号线程数,建议6线程:");

    static JTextArea jtextarea1=new JTextArea(11,23);
    static JTextArea jtextarea2=new JTextArea(11,23);
    static JTextArea jtextarea3=new JTextArea(11,23);
    static JTextArea jtextarea4=new JTextArea(11,23);
    static JTextArea jtextarea5=new JTextArea(11,23);
    static JTextArea jtextarea6=new JTextArea(11,23);

    JScrollPane jscrollPane1= new JScrollPane(jtextarea1);
    JScrollPane jscrollPnae2= new JScrollPane(jtextarea2);
    JScrollPane jscrollPane3= new JScrollPane(jtextarea3);
    JScrollPane jscrollPane4= new JScrollPane(jtextarea4);
    JScrollPane jscrollPane5= new JScrollPane(jtextarea5);
    JScrollPane jscrollPane6= new JScrollPane(jtextarea6);

    JButton jbutton1=new JButton("开始");
    JButton jbutton2=new JButton("停止");

    static Boolean startFlag=false;

    JTextField jtextfield=new JTextField("6",10);
    protected void winSizeSet(){
        jframe.setBounds(250,100,1000,650);//设置窗口 x,y位置  窗口大小 x,y
        //jframe.setDefaultLookAndFeelDecorated(true);//确认一个漂亮的外观
        System.out.println();
        String strImage =XJiangJFrame.class.getProtectionDomain().getCodeSource().getLocation().getPath(); //地址有叹号 转jar后
        System.out.println(strImage+"/resourcess/icon.png");
        ImageIcon imageicon=new ImageIcon(strImage+"/resourcess/icon.png");
        System.out.println();
        jframe.setIconImage(imageicon.getImage());
        jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        jframe.setVisible(true);//显示窗口 true为不透明 默认透明
    }
    protected void addJpanel(){
        jPanel0.setLayout(new GridLayout(2,4,3,10));//装6个jpanel的布局

        //面板添加滚动跳
        jPanel1.add(jlabel1);
        jPanel1.add(jscrollPane1);
        jPanel1.setLayout(new FlowLayout(FlowLayout.CENTER,0,0));

        jPanel2.add(jlabel2);
        jPanel2.add(jscrollPnae2);
        jPanel2.setLayout(new FlowLayout(FlowLayout.CENTER,0,0));

        jPanel3.add(jlabel3);
        jPanel3.add(jscrollPane3);
        jPanel3.setLayout(new FlowLayout(FlowLayout.CENTER,0,0));

        jPanel4.add(jlabel4);
        jPanel4.add(jscrollPane4);
        jPanel4.setLayout(new FlowLayout(FlowLayout.CENTER,0,0));

        jPanel5.add(jlabel5);
        jPanel5.add(jscrollPane5);
        jPanel5.setLayout(new FlowLayout(FlowLayout.CENTER,0,0));

        jPanel6.add(jLabel6);
        jPanel6.add(jscrollPane6);
        jPanel6.setLayout(new FlowLayout(FlowLayout.CENTER,0,0));

        jPanel7.add(jbutton1);
        jPanel7.add(jbutton2);
        jPanel7.add(jlabel7);
        jPanel7.add(jtextfield);

        jPanel0.add(jPanel1);
        jPanel0.add(jPanel2);
        jPanel0.add(jPanel3);
        jPanel0.add(jPanel4);
        jPanel0.add(jPanel5);
        jPanel0.add(jPanel6);
        jPanel0.add(jPanel7);

        this.setButtonAction();

        jframe.add(jPanel0);//往JFrame 添加jPanel1
    }
    public void setButtonAction(){
        jbutton1.addActionListener(
                new ButtonActionListener(){
                    public void actionPerformed(ActionEvent e) {
                                 if(!startFlag)//线程未开始 startFlag 为0
                                 MultiplyThread.startThread(jtextfield.getText());
                    }
                }                   );
        jbutton2.addActionListener(new ButtonActionListener(){
                                    public void actionPerformed(ActionEvent e) {
                                        if(startFlag)  //线程开始为1
                                        MultiplyThread.stopThread();
                                         }
        });
    }
    public static void setJTextareaContent(String str){
        jtextarea6.append(str+"\r\n");
    }
    public static void setJTextareaContent1(String str){
        jtextarea1.append(str+"\r\n");
    }
    public static void setJTextareaContent2(String str){
        jtextarea2.append(str+"\r\n");
    }
    public static void setJTextareaContent3(String str){
        jtextarea3.append(str+"\r\n");
    }
    public static void setJTextareaContent4(String str){
        jtextarea4.append(str+"\r\n");
    }
    public static void setJTextareaContent5(String str){
        jtextarea5.append(str+"\r\n");
    }

}
